<?php
    header('content-type:text/html;charset="utf-8"');
    //定义统一返回格式
    $responseData = array("code" => 0,"message" => "");
    //取出传过来的数据
    $goodname = $_POST["goodname"];
    $number = $_POST["number"];
    $id = $_POST["id"];

    // 1.连接数据库
    $link = mysqli_connect("localhost","root","root");

    // 2.判断是否连接成功
    if(!$link){
        $responseData['code'] = 1;
        $responseData['message'] = "数据库连接失败";
        // 返回到前台页面
        echo json_encode($responseData);
        exit; //结束后续操作
    }

    //3.设置字符集
    mysqli_set_charset($link,"utf8");

    //4.选择数据库
    mysqli_select_db($link,"租售系统");

    //发送
    $sql1 = "UPDATE goods SET stock=stock-'{$number}' WHERE goodname='{$goodname}'";

    //再次发送sql
    $res1 = mysqli_query($link,$sql1);
 
    //返回布尔值
    if($res1){
        //修改成功
        $responseData["message"] = "成功";
        echo json_encode($responseData);
    }else{
        //修改失败
        $responseData["code"] = 2;
        $responseData["message"] = "失败";
        echo json_encode($responseData);
        exit;
    }

    //8.关闭数据库
    mysqli_close($link);
?>